<!DOCTYPE html>
<html>
  <head>
    <title>交易信息</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="../../js/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../js/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="../../css/custom.css" />
	<script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/jquery.easyui.min.js"></script>
	
	<script type="text/javascript">
		$(function(){
			$("#dg").datagrid({
				url: "../../transaction/list",
				
				toolbar:[
					{
					iconCls: "icon-add",
					text:"新增",
					handler: function(){
						$("#add").window("open");
						$("#type").val("add");
						clearForm();
					}},'-',
					{
					iconCls: 'icon-remove',
					text:"删除",
					handler: function(){
						deleteCustomer();
					}}
				],
				pagination: true,
				rownumbers: true,
				onDblClickRow: function(rowIndex,rowData) {
					edit(rowIndex,rowData);
				}
			});
			$("#query").click(function(){
				var wangwangName = $("#wangwangName").val();
				var wxStartDate = $("#wxStartDate").val();
				var wxEndDate = $("#wxEndDate").val();
				$.ajax({
					type: "post",
					url: "../../transaction/list",
					dataType: "json",
					data: {"wangwangName":wangwangName,"wxStartDate":wxStartDate,"wxEndDate":wxEndDate},
					success: function(data) {
						if(null == data) {
							$.messager.alert('warning','查询出现异常');
						}
						$("#dg").datagrid("loadData",data);						
					}
				});
			});
			
		});
		
		function deleteCustomer() {
			var ids = '';
			var keys = $('#dg').datagrid('getChecked');
			$.each(keys, function(index, item){
				ids += item.id+",";
			}); 
			$.ajax({
				type: "post",
				url: "../../transaction/delete",
				dataType: "text",
				data: ids,
				success: function(data) {
					if(data > 0) {
						$.messager.show({
							title: "tips",
							msg: "删除成功",
							timeout: 3000,
							showType: "slide"
						});
					} else {
						$.messager.show({
							title: "tips",
							msg: "删除失败",
							timeout: 3000,
							showType: "slide"
						});
					}
					$("#dg").datagrid('reload');
				}
			});
		}
		
		function edit(rowIndex,rowData) {
			$("#add").window("open");
			//clearForm();
			$("#type").val("update");
			$("#id").val(rowData.id);
			$("#ff").form('load', rowData);
		}
		
		function clearForm(){
			$('#ff').form('clear');
		}
		
		function submitForm(){
			var type = $("#type").val();
			var url = "../../transaction/add";
			if('update' == type) {
				url = "../../transaction/update";
			}
			$('#ff').form('submit',{
				url:url,
				dataType: 'json',
				success: function(result) {
					if(result == '0') {
						$("#add").window("close");
						$.messager.show({
								title: "tips",
								msg: "操作成功",
								timeout: 3000,
								showType: "slide"
							});
						$("#dg").datagrid('reload');
						clearForm();
					} else {
						$.messager.show({
								title: "tips",
								msg: "操作失败，请检查输入信息",
								timeout: 3000,
								showType: "slide"
							});
					}
				},
				failure: function() {
					$("#add").window("close");
					$.messager.alert("新增记录失败");
				},
				onSubmit:function(){
					return true;
					//return $(this).form('enableValidation').form('validate');
				}
			});
		}
		
		function myformatter(date){
			var y = date.getFullYear();
			var m = date.getMonth()+1;
			var d = date.getDate();
			return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
		}
		function myparser(s){
			if (!s) return new Date();
			var ss = (s.split('-'));
			var y = parseInt(ss[0],10);
			var m = parseInt(ss[1],10);
			var d = parseInt(ss[2],10);
			if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
				return new Date(y,m-1,d);
			} else {
				return new Date();
			}
		}
		
		function jsonYearMonthDay(milliseconds) {
			if(null == milliseconds || '' == milliseconds) {
				return '';
			}
		    var datetime = new Date();
		    datetime.setTime(milliseconds);
		    var year = datetime.getFullYear();
		    var month = datetime.getMonth() + 1 < 10 ? "0"
		            + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
		    var date = datetime.getDate() < 10 ? "0" + datetime.getDate()
		            : datetime.getDate();
		    return year + "-" + month + "-" + date;
	    }
	    
	    function fugouAndTuijian(value) {
	    	if('1' == value) {
	    		return '是';
	    	} else {
	    		return '否';
	    	}
	    }
	</script>

  </head>
  
  <body>
  		<div id="tb" class="query">
		微信转账开始日期: <input id="wxStartDate" class="easyui-datebox" style="width:110px" data-options="formatter:myformatter,parser:myparser">
		结束日期: <input id="wxEndDate" class="easyui-datebox" style="width:110px" data-options="formatter:myformatter,parser:myparser"> 
		旺旺: <input class="easyui-textbox" id="wangwangName">
		
		<a href="#" id="query" class="easyui-linkbutton" iconCls="icon-search">Search</a>
		</div>
		<table id="dg" class="easyui-datagrid" title="交易信息" style="width:100%;height:100%;margin-top: 80px;"
				data-options="singleSelect:false,checkOnSelect:true,collapsible:true,sortable:true">
				<thead>
					<tr>
						<th field="ck" checkbox="true"></th>
						<th data-options="field:'id',width:100" hidden="true"/>
						<th data-options="field:'wangwangName',width:120,halign:'center'">旺旺名</th>
						<th data-options="field:'customerName',width:60,halign:'center'">收件人</th>
						<th data-options="field:'custPhone',width:80,halign:'center'">联系电话</th>
						<th data-options="field:'address',width:400,halign:'center'">收件地址</th>
						<th data-options="field:'transactionNum',width:40,halign:'center',align:'center'">件数</th>
						<th data-options="field:'transactionTm',width:100,halign:'center',formatter:jsonYearMonthDay">交易日期</th>
						<th data-options="field:'prodDesc',width:100,halign:'center'">交易成功的款式</th>
						<th data-options="field:'refundTm',width:100,halign:'center',formatter:jsonYearMonthDay">退款时间</th>
						<th data-options="field:'refundReason',width:100,halign:'center'">退款原因</th>
						<th data-options="field:'orderDetail',width:100,halign:'center'">下单详情</th>
						<th data-options="field:'province',width:100,halign:'center'">省份</th>
						<th data-options="field:'city',width:50,halign:'center'">城市</th>
						<th data-options="field:'evaluate',width:200,halign:'center'">评价</th>
						<th data-options="field:'wxTransferDate',width:100,halign:'center',formatter:jsonYearMonthDay">微信转账日期</th>
						<th data-options="field:'wxTransferAmount',width:200,halign:'center'">微信转账金额</th>
						<th data-options="field:'reBuy',width:50,halign:'center',formatter:fugouAndTuijian">复购</th>
						<th data-options="field:'recommend',width:50,halign:'center',formatter:fugouAndTuijian">推荐</th>
						<th data-options="field:'recommender',width:100,halign:'center'">推荐人</th>
						<th data-options="field:'remark',width:200,halign:'center'">备注</th>
					</tr>
				</thead>
		</table>
	<!--  -->
	<div id="add" closed="true" class="easyui-window" title="交易信息" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:600px;height:700px;padding:10px;">
		<form id="ff" class="easyui-form" method="post" data-options="novalidate:true">
			<input id="type" hidden="hidden">
			<input id="id" name="id" hidden="hidden">
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="wangwangName" name="wangwangName" style="width:40%" data-options="label:'旺旺名',required:true">
				<input class="easyui-textbox right_pad" id="customerName" name="customerName" style="width:40%" data-options="label:'收件人',required:true">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="custPhone" name="custPhone" style="width:40%" data-options="label:'联系电话',required:true">
				<input class="easyui-textbox right_pad" id="address" name="address" style="width:40%" data-options="label:'收件地址',required:true">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="transactionNum" name="transactionNum" style="width:40%" data-options="label:'件数',required:true">
				<input class="easyui-datebox right_pad" id="transactionTm" name="transactionTm" style="width:40%" label="交易日期" data-options="formatter:myformatter,parser:myparser,required:true">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="prodDesc" name="prodDesc" style="width:40%" data-options="label:'交易款式',required:true">
				<input class="easyui-datebox right_pad" id="refundTm" name="refundTm" style="width:40%" label="退款时间" data-options="formatter:myformatter,parser:myparser,required:true">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="refundReason" name="refundReason" style="width:40%" data-options="label:'退款原因',required:true">
				<input class="easyui-textbox right_pad" id="orderDetail" name="orderDetail" style="width:40%" data-options="label:'下单详情',required:true">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="province" name="province" style="width:40%" data-options="label:'省份',required:true">
				<input class="easyui-textbox right_pad" id="city" name="city" style="width:40%" data-options="label:'城市',required:true">
			</div>
			<div style="margin-bottom:20px">
				<select class="easyui-combobox" id="evaluate" name="evaluate" label="评价" style="width:40%">
					<option value="">--请选择--</option>
					<option value="好评">好评</option>
					<option value="中评">中评</option>
					<option value="差评">差评</option>
				</select>
				<input class="easyui-datebox right_pad" id="wxTransferDate" name="wxTransferDate" style="width:40%" label="微信转账日期" data-options="formatter:myformatter,parser:myparser,required:true">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="wxTransferAmount" name="wxTransferAmount" style="width:40%" data-options="label:'微信转账金额',required:true">
				<select class="easyui-combobox" id="reBuy" name="reBuy" label="是否复购" style="width:40%">
					<option value="">--请选择--</option>
					<option value="1">是</option>
					<option value="0">否</option>
				</select>
				
			</div>
			<div style="margin-bottom:20px">
				<select class="easyui-combobox" id="recommend" name="recommend" label="是否推荐" style="width:40%">
					<option value="">--请选择--</option>
					<option value="1">是</option>
					<option value="0">否</option>
				</select>
				<input class="easyui-textbox right_pad" id="recommender" name="recommender" style="width:40%" data-options="label:'推荐人',required:true">
			</div>
			<div style="margin-bottom:20px">
				<input class="easyui-textbox" id="remark" name="remark" style="width:90%;height:120px" data-options="label:'备注',multiline:false">
			</div>
		</form>
		<div style="text-align:center;padding:5px 0">
			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">提交</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">重置</a>
		</div>
	</div>
	
  </body>
</html>
